﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ADONetTest1
{
    class Program
    {
        static void Main(string[] args)
        {
            string sql = "server=.;Database=Commodity;uid=sa;pwd=123456";
            SqlConnection sqlConnection = new SqlConnection(sql);
            sqlConnection.Open();
            Console.WriteLine("数据库连接");
            //插入数据 
            Console.WriteLine("插入数据：");
            Console.WriteLine("何许人也：");
            string name = Console.ReadLine();
            Console.WriteLine("年方几何：");
            int age = int.Parse(Console.ReadLine());
            //插入数据到数据库
            var sqlc = "insert into Person(Name,Age)" + "Value('佲伶',20)";

            //修改数据库内容
            sqlc = "update Person set Age = 28 Where Name = '咲葉'";

            //删除数据库内容
            sqlc = "delete from Person Where Name = '言葉'";

            var cmdString = "select * from Indent";
            SqlCommand  command = new SqlCommand(cmdString,sqlConnection);

            var reader = command.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", "订单", "日期", "数量","商品");
            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}", reader["indentId"], reader["date"], reader["quantity"],reader["commodityId"]);
            }
            sqlConnection.Close();

            //DataTable table = new DataTable();             
            //SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdString,sql);
            //sqlDataAdapter.Fill(table);
            //foreach(  DataRow row in table.Rows)
            //{
            //    Console.WriteLine(row["indentId"]);
            //}
         }
    }
}
